package Boundary;

import Entity.Achievements;
import Entity.ModulesGrades;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import static Control.Control.*;
/**
 * @author Group77
 * @version 4.0
 * @description display an operational page for adding achievement
 */
public class AchievementAdd extends Overall{
    /**
     * initialize the Jframe
     *
     * @param number : the name of each frame
     */
    public AchievementAdd(int number) {
        super("add");
        panel1.setLayout(new BorderLayout());
        panel1.setBorder(BorderFactory.createEmptyBorder());
        JButton button0 = new JButton("   Go back   ");
        button0.setBorder(BorderFactory.createRaisedBevelBorder());
        button0.setBackground(Color.cyan);
        button0.setFont(new Font("STSong", Font.BOLD, 25));
        JPanel empty1 = new JPanel();
        empty1.setPreferredSize(new Dimension(100, 10));
        panel1.add(button0, BorderLayout.WEST);
        panel1.add(empty1, BorderLayout.NORTH);
        Add_Component(jfr, gbl, panel1, gbc, 0, 0, 1, 1, 1, 0);


        button0.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jfr.setVisible(false);
                        new AchieveManagement(number);
                        jfr.dispose();
                    }
                }
        );

        JLabel label1 = new JLabel("Student Name :", JLabel.CENTER);
        label1.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        JTextField tf1 = new JTextField(12);
        tf1.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        Box b1 = Box.createHorizontalBox();
        b1.add(label1);
        b1.add(Box.createHorizontalStrut(10));
        b1.add(tf1);
        panel2.add(b1);
        Add_Component(jfr, gbl, panel2, gbc, 0, 2, 1, 1, 1, 0);

        JLabel label2 = new JLabel("Achievement   :", JLabel.CENTER);
        label2.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        JTextField tf2 = new JTextField(12);
        tf2.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        Box b2 = Box.createHorizontalBox();
        b2.add(label2);
        b2.add(Box.createHorizontalStrut(10));
        b2.add(tf2);
        panel3.add(b2);
        Add_Component(jfr, gbl, panel3, gbc, 0, 3, 1, 1, 1, 0);

        JLabel label3 = new JLabel("Experience      :", JLabel.CENTER);
        label3.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        JTextField tf3 = new JTextField(12);
        tf3.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        Box b3 = Box.createHorizontalBox();
        b3.add(label3);
        b3.add(Box.createHorizontalStrut(10));
        b3.add(tf3);
        panel4.add(b3);
        Add_Component(jfr, gbl, panel4, gbc, 0, 4, 1, 1, 1, 0);




        panel7.setBorder(BorderFactory.createEmptyBorder());
        JButton button2 = new JButton("   Confirm   ");
        button2.setBorder(BorderFactory.createRaisedBevelBorder());
        button2.setBackground(Color.LIGHT_GRAY);
        button2.setFont(new Font("TimesRoman", Font.BOLD, 30));
        JPanel emp = new JPanel();
        emp.setPreferredSize(new Dimension(700, 10));
        emp.setBorder(BorderFactory.createEmptyBorder());
        panel7.add(emp);
        panel7.add(button2, BorderLayout.CENTER);
        Add_Component(jfr, gbl, panel7, gbc, 0, 5, 1, 1, 1, 1);


        button2.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jfr.setVisible(false);
                        List<Achievements> AC=json2.readArray(Achievements.class);
                        AC.add(new Achievements(number,tf1.getText(),tf2.getText(),tf3.getText()));
                        json2.writeArray(AC);
                        new AchieveManagement(number);
                        jfr.dispose();
                    }
                }
        );


    }
}
